/**
 * 用户表服务类实现
 * 周捷
 * 2013-12-25
 */
package com.passkeeper.jdbc.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.passkeeper.jdbc.dao.UserMapper;
import com.passkeeper.jdbc.model.User;
import com.passkeeper.jdbc.model.UserExample;
import com.passkeeper.jdbc.service.inteface.IUserService;
import com.passkeeper.util.UtilFunction;

@Service("userService")
public class UserService implements IUserService{

	@Autowired
	private UserMapper mapper;
	
	/*
	 * (non-Javadoc)
	 * @see com.passkeeper.jdbc.service.inteface.IUserService#findUserByUsername(java.lang.String)
	 */
	public User findUserByUsername(String username){
		User user = new User();
		try {
			UserExample example = new UserExample();
			example.createCriteria().andUsernameEqualTo(UtilFunction.doNull(username));
			List<User> userList = mapper.selectByExample(example);
			if(userList!=null && userList.size()==1){
				user=userList.get(0);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return user;
	}
	
	/*
	 * 查找所有用户
	 * 
	 */
	public List<User> findAllUsers(){
		List<User> userList = null;
		try{
			UserExample example = new UserExample();
			example.createCriteria();
			userList = mapper.selectByExample(example);
		}catch(Exception e){
			e.printStackTrace();
		}
		return userList;
	}
	
	public void insert(){
		User user = new User();
		mapper.insert(user);
	}
}
